<template>
    <a-config-provider :locale="locale">
        <div id="app">
            <router-view />
            <audio src="@/assets/music/order.mp3" autoplay muted></audio>
        </div>
    </a-config-provider>
</template>

<script>
import { i18nRender } from '@/locales'
import { domTitle, setDocumentTitle } from '@/utils/domUtil'

export default {
    data() {
        return {}
    },
    sockets: {
        connect() {
            console.log('socket connect =====')
        },
        async res(v) {
            console.log(`监听服务端返回res事件的返回值:${v}`)
        },
        async create(v) {
            console.log('app===', v)
            // const info = this.$store.state.user.info

            // if (info.type !== 1) return

            const audio = await document.querySelector('audio')

            audio.mounted = false

            audio.play()

            this.$notification.open({
                message: '您有新的订单!!!',
                description: v.goods.map(items => items.title),
                icon: <a-icon type="smile" style="color: #108ee9" />
            })

            this.$print.show(v)
            // this.$print.printOrder()
            console.log(`创建订单通知`, v)
        },
        async refund(v) {
            this.$notification.open({
                message: '你有一笔订单退款, 请查看~~',
                description: `订单号:${v.tid}\n商品:${v.titles}`,
                icon: <a-icon type="smile" style="color: #108ee9" />
            })
        },
        async message(v) {
            this.$store.dispatch('Count')
            this.$notification.open({
                message: `${v.message}, 请查看~~`,
                icon: <a-icon type="smile" style="color: #108ee9" />
            })
        },
        syncOrder(v) {
            this.$message.success('订单同步中')
        }
    },
    created() {},
    computed: {
        locale() {
            // 只是为了切换语言时，更新标题
            const { title } = this.$route.meta
            title && setDocumentTitle(`${i18nRender(title)} - ${domTitle}`)

            return this.$i18n.getLocaleMessage(this.$store.getters.lang).antLocale
        }
    },
    mounted() {}
}
</script>
